package cn.mengfly.testnrz.im.client.handler;

import cn.mengfly.testnrz.im.client.ClientSession;
import cn.mengfly.testnrz.im.client.CommandClient;
import cn.mengfly.testnrz.im.client.InvalidFrameException;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;


public class ExceptionHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        System.out.println(cause.getMessage());
        if (cause instanceof InvalidFrameException) {
            ClientSession.getSession(ctx).close();
        } else {
            ctx.close();
            CommandClient.reconnect();
        }
    }
}
